import wepy from 'wepy';
import {
  COMP,
  OPEN_ID,
  COMP_ID
} from './constant';
import api from '@/api/common';


export default class Common {
  // 获取企业信息
  static getCompInfo() {
    return api.getCompInfo()
    .then(res => {
      if(res.code) {
        wepy.setStorageSync(COMP, res.data.comp);
        return res.data.comp
      }
    })
  }
  // 获取comp
  static getComp() {
    let comp = wx.getStorageSync(COMP);
    if(comp) {
      return comp
    }else {
      return []
    }
  }
  // 获取compId
  static getCompId() {
    return this.getComp()[COMP_ID]
  }
  // 获取openId
  static getOpenId() {
    let openId = wx.getStorageSync(OPEN_ID);
    if(openId) {
      return openId
    }
  }
}
